package com.autumn.scheduler.job.trigger;

import org.quartz.CalendarIntervalScheduleBuilder;
import org.quartz.DateBuilder.IntervalUnit;
import org.quartz.JobDetail;
import org.quartz.Trigger;

import com.autumn.scheduler.domain.entities.AutumnJobDetails;
import com.autumn.scheduler.domain.values.SchedulerValue;

/**
 * 日历间隔作业触发器 描述：
 * 
 * @author 杨昌国 2018-03-20 16:56:20
 */
public class CalendarIntervalJobTrigger extends AbstractIntervalJobTrigger {

	/**
	 * 
	 * 
	 * @param timeInterval
	 * @param unit
	 */
	public CalendarIntervalJobTrigger(int timeInterval, IntervalUnit unit) {
		super(timeInterval, unit);
	}

	@Override
	public Trigger createTrigger(JobDetail jobDetail, AutumnJobDetails autumnJobDetail, SchedulerValue schedulerValue) {
		CalendarIntervalScheduleBuilder scheduleBuilder = CalendarIntervalScheduleBuilder.calendarIntervalSchedule()
				.withInterval(this.getTimeInterval(), this.getUnit());
		autumnJobDetail.setCronExpression("");
		autumnJobDetail.setTimeInterval(this.getTimeInterval());
		autumnJobDetail.setTimeIntervalUnit(this.getUnit().toString());
		return this.createTrigger(jobDetail, autumnJobDetail, schedulerValue, scheduleBuilder);
	}

}
